package com.b2c.service;

import com.b2c.mapper.SpecGroupMapper;
import com.b2c.mapper.SpecParamMapper;
import com.mr.service.pojo.BrandEntity;
import com.mr.service.pojo.SpecGroup;
import com.mr.service.pojo.SpecParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @ClassName SpecificationService
 * @Description: TODO
 * @Author kun
 * @Date 2020/7/25
 * @Version V1.0
 **/
@Service
public class SpecificationService {

    @Autowired
    private SpecGroupMapper specGroupMapper;

    @Autowired
    private SpecParamMapper specParamMapper;

    public List<SpecGroup> querySpecGroups(Long cid) {
        Example example=new Example(SpecGroup.class);
        example.createCriteria().andEqualTo("cid",cid);
        return specGroupMapper.selectByExample(example);
    }

    public List<SpecParam> querySpecParams(Long gid,Long cid,Boolean searching,Boolean generic){
        SpecParam t = new SpecParam();
        t.setGroupId(gid);
        t.setCid(cid);
        t.setSearching(searching);
        t.setGeneric(generic);
        return this.specParamMapper.select(t);
    }

    @Transactional
    public void save(SpecGroup entity){

        if(entity.getId() != null){
            specGroupMapper.updateByPrimaryKey(entity);
        }else {
            specGroupMapper.insertSelective(entity);
        }



    }


    @Transactional
    public void deleteSpec(Long id) {


        specGroupMapper.deleteByPrimaryKey(id);

    }

    @Transactional
    public void add(SpecParam entity) {
        if(entity.getId() != null){
            specParamMapper.updateByPrimaryKey(entity);
        }else {
            specParamMapper.insertSelective(entity);
        }

    }
    @Transactional
    public void delete(Long id) {

        specParamMapper.deleteByPrimaryKey(id);
    }
}
